<template>
	<view>
		<u-list @scrolltolower="scrolltolower">
			<u-list-item v-for="(item, index) in indexList" :key="index">
				<u-cell :title="item.name" @click="gotoCarlist(item.series_id)">
					<u-avatar slot="icon" shape="square" size="55" :src="'https://images.weserv.nl/?url='+item.image"
						customStyle="margin: -3px 10px -3px 5px"></u-avatar>
				</u-cell>
			</u-list-item>
		</u-list>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				indexList: [],
				pageIndex: 1,
				brandId: 0,
				// 总条数
				count: 0
			}
		},
		methods: {
			async loadSeries() {
				// 判断是否加载了所有数据
				if (this.count === this.indexList.length && this.count != 0) {
					return
				}
				let {
					data, count
				} = await uni.$get('getAllSeries', {
					brandId: this.brandId,
					pageIndex: this.pageIndex
				})
				console.log(data)
				this.indexList.push(...data)
				this.count = count
			},
			scrolltolower() {
				this.pageIndex++
				this.loadSeries()
			},
			gotoCarlist(seriesId) {
				uni.navigateTo({
					url:"../carlist/carlist?seriesId=" + seriesId
				})
			}
		},
		onLoad({
			brandId
		}) {
			this.brandId = brandId
			this.loadSeries()
		}
	}
</script>

<style>

</style>
